package cn.how2go.api.common;

/**
 * Created by Administrator on 2018/11/9.
 */
public class CommonResult<T> {
    private String code;
    private String message;
    private T result;

    public CommonResult(String code, String message, T result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }

    public CommonResult() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getResult() {
        return result;
    }

    public void setResult(T result) {
        this.result = result;
    }

    /**
     * 成功输出数据，消息messag为空
     * @param result
     * @param <T>
     * @return
     */
    public static<T> CommonResult<T> success(T result){
        return new CommonResult<T>("200","",result);
    }

    /**
     * 错误输出错误消息，实体为null
     * @param message
     * @param <T>
     * @return
     */
    public static<T> CommonResult<T> fail(String message){
        return new CommonResult<T>("500",message,null);
    }
}
